<% add_decidim_meta_tags(
  description: translated_attribute(debate.description),
  title: present(debate).title,
  url: debate_url(debate.id),
  resource: debate) %>

<%
edit_link(
  resource_locator(debate).edit,
  :update,
  :debate,
  debate:
)
%>

<%=
  render partial: "close_debate_modal", locals: {
    debate:,
    form: close_debate_form
  }
%>

<%= render layout: "layouts/decidim/shared/layout_item", locals: { back_path: debates_path, commentable: debate } do %>
  <section class="layout-main__section layout-main__heading">
    <h1 class="h2 decorator">
      <%== present(debate).title(html_escape: true) %>
    </h1>

    <% debate_presenter = debate.presenter %>
    <% if debate.closed? || debate.finished? %>
    <div class="layout-author has_status">
        <span class="alert label">
          <%= t("closed", scope: "decidim.debates.debates.show") %>
        </span>
    </div>
    <% end %>

    <div class="layout-author <%= "has_status" if debate.closed? %>">
      <div class="relative flex items-center justify-center w-full">
        <div class="w-10/12 flex items-center gap-4">
          <%= cell "decidim/author", debate_presenter.author %>
        </div>
        <%= render "decidim/shared/resource_actions", resource: debate do %>
          <%= render "decidim/debates/debates/debate_actions" %>
        <% end %>
      </div>
    </div>
  </section>

  <section class="layout-main__section">
    <div class="editor-content">
      <%= render_debate_description(debate) %>
    </div>
  </section>

  <%= cell "decidim/tab_panels", tab_panel_items %>

  <% if debate.closed? || translated_attribute(debate.instructions).present? || translated_attribute(debate.information_updates).present? %>
    <section class="layout-main__section">
      <%= cell("decidim/announcement", { title: t("debate_conclusions_are", scope: "decidim.debates.debates.show", date: l(debate.closed_at, format: :decidim_short)), body: simple_format(translated_attribute(debate.conclusions)) }, callout_class: "success") if debate.closed? %>

      <%= cell("decidim/announcement", decidim_sanitize_editor_admin(simple_format(translated_attribute(debate.instructions), {}, sanitize: false))) if translated_attribute(debate.instructions).present? %>

      <%= cell("decidim/announcement", decidim_sanitize_editor_admin(simple_format(translated_attribute(debate.information_updates), {}, sanitize: false)), callout_class: "success") if translated_attribute(debate.information_updates).present? %>
    </section>
  <% end %>

  <%= cell("decidim/tags", debate) %>

  <section class="layout-main__section layout-main__buttons" data-buttons>
    <% if allowed_to?(:like, :debate, debate: debate) %>
      <%= cell("decidim/like_block", debate) %>
    <% end %>

    <%= cell "decidim/comments_button", nil %>
    <div class="ml-auto lg:ml-0">
      <%= cell "decidim/share_widget", debate %>
    </div>
  </section>
  <%= cell "decidim/likers_list", debate %>

  <% content_for :aside do %>
  <section class="layout-aside__section">
    <div class="rounded p-4 bg-background mb-4 divide-y divide-gray-3 [&>*]:py-4 first:[&>*]:pt-0 last:[&>*]:pb-0">
      <div class="text-gray-2 space-y-1.5">
        <div class="text-sm flex items-center gap-1">
          <%= icon "calendar-line", class: "inline-block" %>
          <span class="text-gray-2 space-y-1.5"><%= t("start", scope: "decidim.debates.models.debate.fields") %> - <%= t("end", scope: "decidim.debates.models.debate.fields") %></span>
        </div>

        <div class="text-md font-semibold [&>svg]:inline-block">
          <%= format_date_range(debate.start_time, debate.end_time) || t("open_ended", scope: "decidim.debates.debates.show") %>
        </div>
      </div>
      <div class="text-gray-2 space-y-1.5">
        <div class="text-sm grid grid-cols-1">
          <div>
            <span class="block text-center mb-2">
              <%= t("participants_count", scope: "decidim.debates.debates.show") %>
            </span>
            <span class="text-4xl font-bold block text-center"><%= debate_presenter.participants_count %></span>
          </div>
        </div>
      </div>
    </div>
  </section>
<% end %>

  <% content_for :item_footer do %>
    <%= comments_for debate %>
    <ul class="metadata__container layout-main__section" data-metadata-footer>
      <%= content_tag :li, resource_reference(debate), class: "metadata__item" %>
      <%= content_tag :li, resource_version(debate, versions_path: debate_version_path(debate, debate.versions.count)), class: "metadata__item" %>
    </ul>
  <% end %>

<% end %>
